<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>友链管理</title>
<link rel="stylesheet" type="text/css" href="css/easyui.css">
<link rel="stylesheet" type="text/css" href="css/icon.css">
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" language="javascript" src="js/commom.js"></script>
<script type="text/javascript" language="javascript" src="js/operate.js"></script>
<script type="text/javascript">
	var url = "";
	$(document).ready(
			function() {
				dataGridInfo("position_data", "position/datagrid", "",
						"toolbar");
			});
	function editMessage() {
		var row = $('#message_data').datagrid('getSelected');
		if (row) {
			$('#dlg').dialog('open').dialog('setTitle', '查看留言');
			$("#title").get(0).value = row.title;
			$("#department").get(0).value = row.department;
			$("#address").get(0).value = row.address;
			$("#content").get(0).value = row.content;
		}
	}
	
	function add(){
		$("#info").val('');
		$('#dlg').dialog('open').dialog('setTitle', '添加职位');
		$('#fm').form('clear');
		url = 'position/doAdd';
	}
	
	function destory(){
		var row = $('#position_data').datagrid('getSelected');
		if(row) {
			$.messager.confirm('Confirm','你确定要删除选中的数据吗?',function(r){
				if(r){
					$.post('position/doDelete',{id:row.id},function(result){
						if(result.errorMsg){
							$.messager.show({
								title : '错误',
								msg : result.errorMsg
							});
						} else {
							$('#position_data').datagrid('reload');
						}
					});
				}
			});
		} else {
			$.messager.show({
				title : '提示信息',
				msg : '请选择要操作的数据!'
			});
		}
	}
	
	function edit(){
		var row = $('#position_data').datagrid('getSelected');
		if (row) {
			$.post('position/goUpdate',{id:row.id},function(result){
				if(result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#dlg').dialog('open').dialog('setTitle', '修改员工信息');
					$('#fm').form('load', result);
				}
			});
			url = 'position/doUpdate?department.id=' + row.id;
		}
	}
	
	function savePosition() {
		$('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#dlg').dialog('close'); // close the dialog
					$('#position_data').datagrid('reload'); // reload the user data
				}
			}
		});
	}
</script>
</head>
<body>
	<div class="easyui-panel" data-options="fit:true" style='border: none'>
		<div class="easyui-layout" data-options="fit:true"
			style='border: none'>
			<div id='sss' data-options="region:'center'" style='border: none'>
				<table style='border: 1px solid red' id="position_data"
					class="easyui-datagrid">
					<thead>
						<tr>
							<th data-options="field:'id',width:30,align:'center'">编号</th>
							<th data-options="field:'name',width:80,align:'center'">职位名称</th>
							<th data-options="field:'level',width:160,align:'center'">职位级别</th>
						</tr>
					</thead>
				</table>
				<div id="toolbar">
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-add" plain="true" onclick="add()">添加职位</a>
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-remove" plain="true" onclick="destory()">删除职位</a>
					<a href="javascript:void(0)" class="easyui-linkbutton"
						iconCls="icon-edit" plain="true" onclick="edit()">修改职位</a>
				</div>

				<div id="dlg" class="easyui-dialog"
					style="width: 500px; height: 400px; padding: 10px 20px"
					closed="true" buttons="#dlg-buttons">
					<div class="ftitle">职务信息</div>
					<form id="fm" method="post">
						<div class="fitem">
							<label>职务名称:</label> 
							<input id="id" name="position.id" name="position.id" type="hidden">
							<input id='title' name="position.name" type='text' style='width:270px;'>
						</div>
						<div class="fitem">
							<label>职务级别:</label> 
							<select id="level" class="easyui-combobox" name="position.level" required="required" style="width:150px">
								<option value="1">1</option>
								<option value="2">2</option>
								<option value="3">3</option>
								<option value="4">4</option>
								<option value="5">5</option>
								<option value="6">6</option>
								<option value="7">7</option>
								<option value="8">8</option>
								<option value="9">9</option>
								<option value="10">10</option>
							</select><span style="color: green">*数字越小，级别越高</span>
						</div>
					</form>
				</div>
				<div id="dlg-buttons">
					 <a href="javascript:void(0)" class="easyui-linkbutton c6"
					   iconCls="icon-ok" onclick="savePosition()" style="width: 90px">确定</a>
					<a href="javascript:void(0)" class="easyui-linkbutton" 
					   iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
				</div>
			</div>
		</div>
	</div>
</body>
</html>